package Decorator;

import Decorator.component.Beverage;
import Decorator.componentSub.DarkRoast;
import Decorator.componentSub.Espresso;
import Decorator.decoratorInterfaceImpl.Mocha;
import Decorator.decoratorInterfaceImpl.Whip;

/**
 * 装饰者模式——动态地将责任附加到对象上。若要拓展功能，装饰者提供了比继承更有弹性的替代方案
 * @Author: pengzx
 * @Description:
 * @Date: 14:46 2017/9/6
 * @Modified by: 1.0
 */
public class Demo {
    public static void main(String[] args){
        //不需要调料的Espresso
        Beverage beverage = new Espresso();
        System.out.println(beverage.getDescribe()+" $"+ beverage.cost());
        System.out.println("----------------------------------------------------------");
        Beverage beverage1 = new DarkRoast();//创建一个DarkRoast

        beverage1 = new Mocha(beverage1);//用Mocha装饰它
        beverage1 = new Mocha(beverage1);//用第二个Mocha装饰
        beverage1 = new Whip(beverage1);//用Whip装饰
        System.out.println(beverage1.getDescribe()+" $"+beverage1.cost());
        System.out.println("----------------------------------------------------------");

    }
}
